"""
          1.打开网址
          2.定位元素
          3.输入
          4.点击
          5.关闭
          6.等待
          ... ...
"""
from selenium import webdriver
from time import sleep


# create browser
def open_browser(type_):
    try:
        driver = getattr(webdriver, type_)()
    except Exception as e:
        print(e)
        driver = webdriver.Edge()
    return driver


class Key:

    # init
    def __init__(self, type_):
        self.driver = open_browser(type_)
        self.driver.implicitly_wait(10)

    # get
    def open(self, url):
        self.driver.get(url)

    # locate
    def locate(self, name, value):
        return self.driver.find_element(name, value)

    # input
    def input(self, name, value, txt):
        self.locate(name, value).send_keys(txt)

    # click
    def click(self, name, value):
        self.locate(name, value).click()

    # sleep
    def sleep(self, time_):
        sleep(time_)

    # quit
    def quit(self):
        self.driver.quit()
